import {isNull, getSidebarDataTemp, getSidebarData, getSidebarDataThisDay,  } from '@/utils/utils'
import { setLocalStorage, getLocalStorage} from '@/utils/localStorage' // removeLocalStorage
const storageKeySeason = 'SEASONSTORAGE'
const storageKeyContinuityNum = 'CONTINUITYNUMSTORAGE'
const appoRepair = !window.g.REPAIR_UO
const _startTime = '00:00'
const _endTime = '24:00'

// 多级数组摊平处理 [1,2,[3,4],5] => [1,2,3,4,5]
export function flattenDeep(arr1) {
    return arr1.reduce((acc, val) => Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val), []);
}
// 获取时段号源的连续号源字段
export function getContinuityNum() {
    let isCN = getLocalStorage(storageKeyContinuityNum)
        // // console.log('isCN', isCN)
        // // console.log('isCN', isCN==1)
    return isCN == 1 ? true : false
}
// 设置时段号源的连续号源字段
export function setContinuityNum(value) {
    setLocalStorage(storageKeyContinuityNum, value)
}
// 获取时令设置的默认时令数据
export function getSeasonDefault() {
    let seasonArr = JSON.parse(getLocalStorage(storageKeySeason))
    // console.log('时间轴从时令数据中获取seasonArr=>getLocalStorage=>SEASONSTORAGE', seasonArr)
        // 获取默认时令，如果没有设置默认时令，获取第一个对象时令
    let ds = Object.keys(seasonArr).find(k => seasonArr[k].isDefault)
    // console.log('!!!!!!!ds!!!!!!!!!', ds)
    ds = ds ? ds : Object.keys(seasonArr)[0]
    let resds = seasonArr[ds]
    resds.season = ds
    return resds
}
// 获取时令设置的班次时间
export function getCheckClassBySeason(checkClassSettings) {
    let startTime = ''
    let endTime = ''
    let startNum = 1
    if (checkClassSettings) {
        const ccs = checkClassSettings
        startTime = `${ccs.startHour}:${ccs.startMinute}`
        endTime = `${ccs.endHour}:${ccs.endMinute}`
        startNum = 1
        const ns = ccs.numberSettings
        if (ns && ns.length > 0) {
            startNum = ns[0].startNum
        }
    }
    return { startTime, endTime, startNum }
}
/**
 * 排班管理，日程安排，
 * */

/**
 * 计算时间的分钟数
 * @param {*} time 时间 10:00
 * return 600 (10*60 + 0*1)
 */
export function getCalTimeMinute(time) {
    if (!time) return 0
    const _t = time.split(':')
    return _t[0] * 60 + _t[1] * 1
}
/**
 * 计算时间的秒数
 * @param {*} time 时间 10:00:00
 * return 36000 (10*3600 + 0*60 + 0*1)
 */
export function getCalTimeSecond(time) {
  // // console.log('getCalTimeSecond', time)
    if (!time) return 0
    const _t = time.split(':')
    if (_t.length > 2) {
        return _t[0] * 3600 + _t[1] * 60 + _t[2] * 1
    } else {
        return _t[0] * 3600 + _t[1] * 60
    }
}
/**
 * 获取计算传参的所有和
 * @returns
 */
export function getArgsCalNum() {
  // console.log('arguments', arguments)
  const args = [...arguments]
  let count = 0
  for (let arg of args) {
    if (arg) {
      count += arg * 1
    }
  }
  return count
}

/**
 * 获取预约时段周日期
 * @param {*} d 当前时间
 *  arguments[1] 判断是否需要年
 *  arguments[2] 传入的拼接字符
 * @returns 当前时间一周的日期数组
 */
export function getWeekStartEndDate(d) {
    let hasYear = arguments[1] != false
    let hasSep = arguments[2]
    return new Promise(resolve => {
        const date = new Date(d)
        let year = date.getFullYear() // 年
        let month = date.getMonth() // 月
        let day = date.getDate() // 日
        let week = date.getDay() // 周
        week = week > 0 ? week : 7
        let weekDate = []
        for (let i = 0; i < 7; i++) {
            weekDate.push(getFormatDate(new Date(year, month, day - week + i + 1), hasYear, hasSep))
        }
        // console.log('weekDate:====', weekDate)
        resolve(weekDate)
    })
}

function getFormatDate(newTime, hasYear, hasSep) {
    const date = new Date(newTime)
    const seperator1 = hasSep || '-'
    let year = date.getFullYear() // 年
    let month = date.getMonth() + 1 // 月
    month = month < 10 ? '0' + month : month
    let strDate = date.getDate() // 日
    strDate = strDate < 10 ? '0' + strDate : strDate

    let currentdate = hasYear ? year + seperator1 + month + seperator1 + strDate : month + seperator1 + strDate
        // 一周的日期
    return currentdate
}

/**
 * 根据班次名称对，全天的对应班次号源数组排序及起始号码更新
 * @param {array} appointment 整天的班次号源数组
 * @param {string} checkClass 班次名称
 * @param {boolean} continuation 号源号码是否连续
 * @param {boolean} appoRepair 是否补充中间时段
 * @returns
 */
export function getAppointmentSametype(appointment, checkClass, continuation, checkClassData) {
  // console.log(7777)
  return new Promise(async resolve => {
    let _appoArr = []
    if (getContinuityNum()) {
      // flattenDeep多级数组摊平处理 [1,2,[3,4],5] => [1,2,3,4,5]
      _appoArr = flattenDeep(appointment)
    } else {
      appointment.forEach(appoList => {
          appoList.forEach(appo => {
              if (appo.checkClass === checkClass || !checkClass) {
                  _appoArr.push(appo)
              }
          })
      })
    }
    await calAppoInitialNum(_appoArr, checkClass, continuation, checkClassData)
    resolve(appointment)
  })
}
export function getScheduleAppoSametype(scheduledata, continuation, checkClassData) {
  return new Promise(async resolve => {
    for (let i = 0; i < scheduledata.length; i++) {
        const sched = scheduledata[i]
        let appoList = JSON.parse(JSON.stringify(sched.appointment))
        // flattenDeep多级数组摊平处理 [1,2,[3,4],5] => [1,2,3,4,5]
        appoList = flattenDeep(appoList)
        for (let j = 0; j < appoList.length; j++) {
            const appo = appoList[j]
            await getAppointmentSametype(sched.appointment, appo.checkClass, continuation, checkClassData)
        }
    }
    resolve(scheduledata)
  })
}
/**
 * 根据班次名称对，全天的对应班次号源数组排序及起始号码更新
 * @param {array} appointment 整天的班次号源数组
 * @param {string} continuation 号源号码是否连续
 * @param {string} checkClassData 班次名称
 * @param {string} appointmentDate 号源当天日期
 * @returns
 */
export function getAppointmentSametypeOnline(appointment, continuation, checkClassData, appointmentDate) {
  // console.log('==appointment==', appointment) // appointment数据已经有问题了  下面是否可以补救回来
  // console.log('continuation', continuation)
  // console.log('checkClassData', checkClassData)
  if (isNull(checkClassData)) {
    checkClassData = getSidebarDataTemp() || getSidebarData()
  }
  // console.log('appointmentDate', appointmentDate)
  return new Promise(async resolve => {
    const apps = JSON.parse(JSON.stringify(appointment))
    // console.log('过滤之前的apps', apps)
    const resAppoArr = []
    const appoList = flattenDeep(apps).filter(ap => !ap.isAddBox)
    for (let i = 0; i < apps.length; i++) {
      const capp = apps[i].filter(item => !item.isAddBox)
      if (capp.length) {
        const appoTitle = getSeasonDateTitle({
            appointmentDate: appointmentDate,
            beginTime: capp[0].beginTime,
            endTime: capp[0].endTime,
            checkClassData
        })
        const _apps = await calAppoInitialNum(appoList, appoTitle, continuation, checkClassData, i)
        resAppoArr.push(_apps)
      } else {
        let nowSidebarData = checkClassData[i]
        const _apps = await calAppoInitialNum(appoList, nowSidebarData.title, continuation, checkClassData, i)
        resAppoArr.push(_apps)
      }
    }
    resolve(resAppoArr)
  })
}
/**
 * @param {Object} scheduledata 本周的号源模板数据(周一到周日)
 * @param {Object} continuation 号源是否连续
 * @param {Object} checkClassData 排班列表竖向时间维度
 */
export function getScheduleAppoSametypeOnline(scheduledata, continuation, checkClassData, isTemp) {
  // console.log('meimei scheduledata', JSON.stringify(scheduledata))
  // console.log('meimei continuation', continuation)
  // console.log('meimei checkClassData', checkClassData)
  return new Promise(async resolve => {
      for (let i = 0; i < scheduledata.length; i++) {
          const sched = scheduledata[i]
          let day = sched.dateFull && sched.dateFull.substring(0, 10)
          // console.log('day=>', day)
          // const timeObj = _sbData[sidebarIndex]
          // const sidebarIndexNext = sidebarIndex + 1
          let timeObj = ''
          // console.log('=====isTemp=====', isTemp)
          // console.log('=====day=====', day)
          if (day && !isTemp) {
            timeObj = getSidebarDataThisDay(day)
          }
          // console.log('timeObj=>', timeObj)
          const ra = await getAppointmentSametypeOnline(sched.appointment, continuation, isTemp ? checkClassData : timeObj, sched.dateFull)
          sched.appointment = ra
      }
      resolve(scheduledata)
  })
}
/**
 * 获取当前时令
 */
export function getNowSeasonData() {
  // 获取缓存中的冬夏时令数据
  const seasonArr = JSON.parse(getLocalStorage(storageKeySeason))
  // console.log('seasonArr', seasonArr)
  const _d = new Date()
  const nowMonth = _d.getMonth() + 1
  let nowSeasionObj = ''
  let j = ''
  for (let k in seasonArr) {
    // console.log('k', k)
    j = k
    let sn = seasonArr[k]
    // console.log('sn', sn)
    // 夏时令的判断方法
    if ((sn.endMonth > sn.startMonth && nowMonth >= sn.startMonth && nowMonth <= sn.endMonth)) {
      nowSeasionObj = seasonArr[k]
      break
    }
    // 冬时令的判断方法
    if (sn.endMonth < sn.startMonth && (nowMonth >= sn.startMonth || nowMonth <= sn.endMonth)) {
      nowSeasionObj = seasonArr[k]
      break
    }
  }
  // console.log(`当前时令：${j}`, nowSeasionObj)
  return nowSeasionObj
}
/**
 * @param {Object} data {appointmentDate,beginTime,endTime} =>{日期，开始时间，结束时间}
 */
export function getSeasonDateTitle(data) {
  // console.log('##############getSeasonDateTitle#############     start     ##########', data)
  let { appointmentDate, beginTime, endTime, checkClassData } = data
  // console.log(`被判定的时间范围beginTime~endTime：${beginTime}~${endTime}`)
  // 判断当前时间段时当前时令中的哪个班次？
  let className = '' // 班次名称
  // 当前时间段开始时间时间戳(分)
  let beginTimeTemp = beginTime.split(':')[0] * 60 + beginTime.split(':')[1] * 1
  // 当前时间段结束时间时间戳(分)
  let endTimeTemp = endTime.split(':')[0] * 60 + endTime.split(':')[1] * 1
  // 思路一，根据时间轴来判断开始时间属于哪个班次
  // 获取时间轴
  let sidebarData = checkClassData || getSidebarDataTemp() || getSidebarData()
  // console.log('appointmentDate', appointmentDate)
  // console.log('checkClassData', checkClassData)
  // console.log('打印时间轴数据sidebarData', sidebarData)
  if (isNull(checkClassData)) {
    checkClassData = sidebarData
  }
  // console.log('checkClassData', checkClassData)
  // 寻找当前所要判断的时间段名称
  // console.log('==>sidebarData', sidebarData)
  sidebarData.forEach(item => {
    // 当前班次时间轴的时间戳（分）
    let sidebarBeginTemp = item.start.split(':')[0] * 60 + item.start.split(':')[1] * 1
    let sidebarEndTemp = item.end.split(':')[0] * 60 + item.end.split(':')[1] * 1
    // 当前时间段若在时间轴班次范围内，则100%判定为属于当前时间轴的班次  ||  若当前时间段只有开始时间在时间轴班次范围内，则以开始时间判定所属班次
    if ((beginTimeTemp >= sidebarBeginTemp && endTimeTemp < sidebarEndTemp) || (beginTimeTemp >= sidebarBeginTemp && beginTimeTemp < sidebarEndTemp)) {
      className = item.title
    }
  })
  // console.log(`被判定的时间范围beginTime~endTime：${beginTime}~${endTime}, 判定结果为：${className}`)
  // console.log('##############getSeasonDateTitle#################  END  ##################')
  // // console.log('resObjTit', resObjTit, appointmentDate, beginTime, endTime )
  return className
}
/**
 * 计算当前选中的号源的时段设置，如：起始号码。。。
 * @param {*} dateObj 选中的号源日期数据
 * @param {*} time 选中的时段范围
 * @returns
 */
export function getSeasonDateInfo(dateObj, time) {
    const seasonArr = JSON.parse(getLocalStorage(storageKeySeason))
    // console.log('seasonArr==', seasonArr)
    const _d = new Date(dateObj.dateFull)
    const _dm = _d.getMonth() + 1
    const _dd = _d.getDate()
    const st = time.split('-')[0]
    const et = time.split('-')[1]
    const sth = st.split(':')[0] * 1
    const sts = st.split(':')[1] * 1
    const eth = et.split(':')[0] * 1
    const ets = et.split(':')[1] * 1
    const stn = sth * 60 + sts
    const etn = eth * 60 + ets
        // // console.log(stn, etn)
    let resObj = null

    for (let k in seasonArr) {
        const sn = seasonArr[k]
        if (
            (sn.endMonth > sn.startMonth && _dm >= sn.startMonth && _dm <= sn.endMonth) ||
            (sn.endMonth < sn.startMonth && (_dm >= sn.startMonth || _dm <= sn.endMonth))
        ) {
            const checkClassArr = sn.checkClassSettings
            for (let j in checkClassArr) {
                const _cc = checkClassArr[j]
                const sn = _cc.startHour * 60 + _cc.startMinute * 1
                const en = _cc.endHour * 60 + _cc.endMinute * 1
                if (
                    stn >= sn && etn <= en
                ) {
                    resObj = _cc.numberSettings[0]
                }
            }
        }
    }
    // // console.log(resObj)
    return resObj
}
const sortFscFun = (a, b) => {
    const aa = a.start.split(':')[0] * 60 + a.start.split(':')[1] * 1
    const bb = b.start.split(':')[0] * 60 + b.start.split(':')[1] * 1
    return aa - bb
}

//  设置班次的对象模板
const sidebarClassItem = {
  title: '',
  titleLab: '',
  defaultMinute: 30,
  start: '',
  end: '',
  barHeight: 0,
  numberSettings: [],
  timegather: [],
  zanc: {
      // 用户切换号源模板组件时的组件配置
      hbh: '', // 班次高度 收起
      htg: [], // 班次时段数组 收起
      sbh: '', // 班次高度 展开
      stg: [] // 班次时段数组 展开
  },
  special: false, // 特定班次
  sidebarHide: true
}
/**
 * 获取时令规则数据，当前时间时令规则
 * @param {*} resSeasonData 时令规则数据
 * @param {*} dateTime 当前时间
 * @param {*} isAllTime 判断是否为所有时间
 * @param {*} seasonKey 时令
 * @param {*} usedDefault 使用默认时令，号源模板设置使用
 * @returns 排班管理规则数据
title: '夏令时',
startMonth: '5.1',
endMonth: '9.30',
sidebardata: [{
  title: '上午班',
  defaultMinute: '30',
  start: '08:00',
  end: '12:00',
  barHeight: 0,
  numberSettings: [],
  timegather: []
}]
 */
export function seasonCalCurrDate(resSeasonData, dateTime, isAllTime, seasonKey, usedDefault) {
  // console.log('resSeasonData', resSeasonData)
  // console.log(`resSeasonData:${resSeasonData}, dateTime:${dateTime}, isAllTime:${isAllTime}, seasonKey:${seasonKey}, usedDefault:${usedDefault}`)
  const spec = '-'
  const cDate = new Date(dateTime)
  const cY = cDate.getFullYear()
  const cM = cDate.getMonth() + 1
  const cD = cDate.getDate()
  const isFullTime = window.g.SEASON_FSC // 配置文件控制是否使用全时令设置时段，且可使用时令切换时段时间轴
  // console.log(cY, cM, cD)
  const rsData = {...resSeasonData }
  setLocalStorage(storageKeySeason, JSON.stringify(resSeasonData))
  let season = {
      title: '',
      startMonth: '',
      endMonth: '',
      sidebardata: []
  }
  let sbData = []
  let defaultKey = ''
  defaultKey= Object.keys(rsData).find(k => rsData[k].isDefault)
  // console.log('==defaultKey==', defaultKey)
  defaultKey = defaultKey ? defaultKey : Object.keys(rsData)[0]
  // if (usedDefault) {
  //   // 获取默认时令，如果没有设置默认时令，获取第一个对象时令
  //   defaultKey= Object.keys(rsData).find(k => rsData[k].isDefault)
  //   defaultKey = defaultKey ? defaultKey : Object.keys(rsData)[0]
  // } else {
  //   let month = Number(dateTime.substring(5, 7))
  //   let day = Number(dateTime.substring(8, 10))
  //   for (let k in rsData) {
  //     const sitem = rsData[k]
  //     // month:5~10 10~4
  //     if (month >= sitem.startMonth && month <= sitem.endMonth && day >= sitem.startDay) {
  //       defaultKey = k
  //       break
  //     }
  //     if (month >= sitem.startMonth && month >= sitem.endMonth && day >= sitem.startDay || month <= sitem.startMonth && month <= sitem.endMonth && day <= sitem.endDay) {
  //       defaultKey = k
  //       break
  //     }
  //   }
  // }
  // console.log('=======rsData=======', rsData)
  for (let k in rsData) {
    // console.log('===========k==============', k)
    // console.log('defaultKey', defaultKey)
    // 时令
    const sitem = rsData[k]
    if (usedDefault && k === defaultKey) {
      // 使用默认时令的班次数据
      season.title = k
      season.startMonth = sitem.startMonth + spec + sitem.startDay
      season.endMonth = sitem.endMonth + spec + sitem.endDay

      const checkClassItem = sitem.checkClassSettings
      for (let t in checkClassItem) {
        // 时段
        const st1 = checkClassItem[t].startHour < 10 ? '0' + checkClassItem[t].startHour * 1 : checkClassItem[t].startHour
        const st2 = checkClassItem[t].startMinute < 10 ? '0' + checkClassItem[t].startMinute * 1 : checkClassItem[t].startMinute
        const et1 = checkClassItem[t].endHour < 10 ? '0' + checkClassItem[t].endHour * 1 : checkClassItem[t].endHour
        const et2 = checkClassItem[t].endMinute < 10 ? '0' + checkClassItem[t].endMinute * 1 : checkClassItem[t].endMinute
        let checkClassItemObj = Object.assign({}, sidebarClassItem)
        checkClassItemObj.title = t
        checkClassItemObj.titleLab = t
        checkClassItemObj.defaultMinute = checkClassItem[t].defaultMinute
        checkClassItemObj.start = st1 + ':' + st2
        checkClassItemObj.end = et1 + ':' + et2
        checkClassItemObj.numberSettings = checkClassItem[t].numberSettings
        checkClassItemObj.end = checkClassItemObj.end === '23:59' ? '24:00' : checkClassItemObj.end
        sbData.push(checkClassItemObj)
      }
    } else if (!usedDefault && k === defaultKey) {
        // console.log('============usedDefault=============', usedDefault)
        const checkClassItem = sitem.checkClassSettings
        // console.log('isFullTime', isFullTime)
        // console.log('seasonKey', seasonKey)
        // console.log('==sitem==', sitem)
        if (isFullTime === 'full' && seasonKey && seasonKey === k) {
          season.title = k
          season.startMonth = sitem.startMonth + spec + sitem.startDay
          season.endMonth = sitem.endMonth + spec + sitem.endDay
        } else if (
          (sitem.endMonth > sitem.startMonth && cM >= sitem.startMonth && cM <= sitem.endMonth) ||
          sitem.endMonth < sitem.startMonth && (cM >= sitem.startMonth || cM <= sitem.endMonth)) {
          // // console.log('season:================', k)
          // 设置当前时间的时令数据
          season.title = k
          season.startMonth = sitem.startMonth + spec + sitem.startDay
          season.endMonth = sitem.endMonth + spec + sitem.endDay
        } else {
          season.title = k
          season.startMonth = sitem.startMonth + spec + sitem.startDay
          season.endMonth = sitem.endMonth + spec + sitem.endDay
        }
        // season.title === k && defaultKey == season.title
        // console.log('season', season) // season本身就有问题了？还是被后面影响了
        // console.log('season.title', season.title)
        // console.log('k', k)
        // console.log('defaultKey', defaultKey)
        // if (isMax && isFullTime !== 'full') {
        //   // 获取所有时令的最大范围时段
        //   for (let t in checkClassItem) {
        //     const hasSdIndex = sbData.findIndex(item => item.title === t)
        //     if (hasSdIndex >= 0) {
        //       const hasSdItem = sbData[hasSdIndex]
        //       const sh = checkClassItem[t].startHour
        //       const sm = checkClassItem[t].startMinute
        //       const eh = checkClassItem[t].endHour
        //       const em = checkClassItem[t].endMinute
        //       let _sh = hasSdItem.start.split(':')[0]
        //       let _sm = hasSdItem.start.split(':')[1]
        //       let _eh = hasSdItem.end.split(':')[0]
        //       let _em = hasSdItem.end.split(':')[1]
        //       if ((sh * 60 + sm * 1) < (_sh * 60 + _sm * 1)) {
        //           // 判断已有时段开始时间的大小
        //           _sh = sh
        //           _sm = sm
        //       }
        //       if ((eh * 60 + em * 1) > (_eh * 60 + _em * 1)) {
        //           // 判断已有时段结束时间的大小
        //           _eh = eh
        //           _em = em
        //       }
        //       const st1 = _sh < 10 ? '0' + _sh * 1 : _sh
        //       const st2 = _sm < 10 ? '0' + _sm * 1 : _sm
        //       const et1 = _eh < 10 ? '0' + _eh * 1 : _eh
        //       const et2 = _em < 10 ? '0' + _em * 1 : _em

        //       sbData[hasSdIndex].start = st1 + ':' + st2
        //       sbData[hasSdIndex].end = et1 + ':' + et2
        //           // // console.log(sbData[hasSdIndex].numberSettings[0].startNum , checkClassItem[t].numberSettings[0].startNum)
        //       if (sbData[hasSdIndex].numberSettings[0].startNum < checkClassItem[t].numberSettings[0].startNum) {
        //           sbData[hasSdIndex].numberSettings = JSON.parse(JSON.stringify(checkClassItem[t].numberSettings))
        //       }
        //     } else {
        //       // 时段
        //       const st1 = checkClassItem[t].startHour < 10 ? '0' + checkClassItem[t].startHour * 1 : checkClassItem[t].startHour
        //       const st2 = checkClassItem[t].startMinute < 10 ? '0' + checkClassItem[t].startMinute * 1 : checkClassItem[t].startMinute
        //       const et1 = checkClassItem[t].endHour < 10 ? '0' + checkClassItem[t].endHour * 1 : checkClassItem[t].endHour
        //       const et2 = checkClassItem[t].endMinute < 10 ? '0' + checkClassItem[t].endMinute * 1 : checkClassItem[t].endMinute
        //       let checkClassItemObj = Object.assign({}, sidebarClassItem)
        //       checkClassItemObj.title = t
        //       checkClassItemObj.titleLab = t
        //       checkClassItemObj.defaultMinute = checkClassItem[t].defaultMinute
        //       checkClassItemObj.start = st1 + ':' + st2
        //       checkClassItemObj.end = et1 + ':' + et2
        //       checkClassItemObj.numberSettings = checkClassItem[t].numberSettings
        //       checkClassItemObj.end = checkClassItemObj.end === '23:59' ? '24:00' : checkClassItemObj.end
        //       // console.log('push => checkClassItemObj', checkClassItemObj)
        //       sbData.push(checkClassItemObj)
        //     }
        //   }
        // } else
        if (season.title === k && defaultKey == season.title) { //  && defaultKey == season.title
          // console.log('不默认，必定进入这里')
          // 只获取当前时间的时令数据
          // console.log('checkClassItem', checkClassItem)
          for (let t in checkClassItem) {
            // 时段
            const st1 = checkClassItem[t].startHour < 10 ? '0' + checkClassItem[t].startHour * 1 : checkClassItem[t].startHour
            const st2 = checkClassItem[t].startMinute < 10 ? '0' + checkClassItem[t].startMinute * 1 : checkClassItem[t].startMinute
            const et1 = checkClassItem[t].endHour < 10 ? '0' + checkClassItem[t].endHour * 1 : checkClassItem[t].endHour
            const et2 = checkClassItem[t].endMinute < 10 ? '0' + checkClassItem[t].endMinute * 1 : checkClassItem[t].endMinute
            let checkClassItemObj = Object.assign({}, sidebarClassItem)
            checkClassItemObj.title = t
            checkClassItemObj.titleLab = t
            checkClassItemObj.defaultMinute = checkClassItem[t].defaultMinute
            checkClassItemObj.start = st1 + ':' + st2
            checkClassItemObj.end = et1 + ':' + et2
            checkClassItemObj.numberSettings = checkClassItem[t].numberSettings
            checkClassItemObj.end = checkClassItemObj.end === '23:59' ? '24:00' : checkClassItemObj.end
            sbData.push(checkClassItemObj)
          }
        }
    }
  }
  sbData.sort(sortFscFun)
  // console.log('seasonCalCurrDate=>sbData', sbData)
  // console.log('seasonCalCurrDate=>isAllTime', isAllTime)
  // console.log('seasonCalCurrDate=>isFullTime', isFullTime)
  season.sidebardata = isAllTime && isFullTime !== 'full' ? calSetOtherTime(sbData) : sbData
  return season
}

// 获取特定时令的班次时间
export function getSeasonSchedule(season) {
    return new Promise(async resolve => {
        // resSeasonData, dateTime, isMax, isAllTime, seasonKey
        const seasonArr = JSON.parse(getLocalStorage(storageKeySeason))
        const resSeason = await seasonCalCurrDate(seasonArr, '', false, season)
        // console.warn('getSeasonSchedule:', resSeason)
        resolve(resSeason)
    })
}

// 计算班次时段的全天时间段
const calSetOtherTime = function(data) {
  let sdata = data
  let rdata = []
  let st = '00:00' // 开始时间
  let et = '24:00' // 结束时间
  // console.log('sdata,sdata.len', sdata, sdata.length)
  if (sdata.length > 0) {
      sdata.forEach(item => {
          const stn = st.split(':')[0] * 60 + st.split(':')[1] * 1
          // console.log('新_2', stn)
          // console.log('新_3', item)
          // console.log('新_4', item.start)
          const istn = item.start.split(':')[0] * 60 + item.start.split(':')[1] * 1
          // console.log('新_5', istn)
          if (istn > stn) {
              if (appoRepair) {
                  item.start = st
                  item.numberSettings.forEach(ns => {
                      // console.log('ns===>', ns)
                      ns.startHour = st.split(':')[0] * 1
                      ns.startMinute = st.split(':')[1] * 1
                  })
              } else {
                  const _nobj = Object.assign({}, sidebarClassItem)
                  _nobj.title = item.title
                  _nobj.titleLab = item.title + '(新_' + (rdata.length + 1) + ')'
                  _nobj.special = true
                  _nobj.sidebarHide = true
                  _nobj.start = st
                  _nobj.end = item.start
                  _nobj.numberSettings = [{
                      endHour: _nobj.end.split(':')[0] * 1,
                      endMinute: _nobj.end.split(':')[1] * 1,
                      preKey: "",
                      startHour: _nobj.start.split(':')[0] * 1,
                      startMinute: _nobj.start.split(':')[1] * 1,
                      startNum: 1
                  }]
                  rdata.push(_nobj)
              }
          }
          // // console.log(item.end)
          st = item.end === '23:59' ? '24:00' : item.end
          rdata.push(item)
      })
  }
  // 判断最后一个是否已经到 24 点，如果没有，再加上最后的时间区间
  // console.log('打印当前时令班次时间区间rdata====>', rdata)
  // console.log('st=====>', st)
  // console.log('et=====>', et)
  const stn = st.split(':')[0] * 60 + st.split(':')[1] * 1
  const etn = et.split(':')[0] * 60 + et.split(':')[1] * 1
  // console.log('stn--->etn', stn, etn)
  if (etn > stn) {
      if (appoRepair) {
          if (rdata.length > 0) {
              const _item = rdata[rdata.length - 1]
              _item.end = et
              _item.numberSettings.forEach(ns => {
                  ns.endHour = et.split(':')[0] * 1
                  ns.endMinute = et.split(':')[1] * 1
              })
          }
      } else {
          const _nobj = Object.assign({}, sidebarClassItem)
          // console.log('_nobj=====>', _nobj)
          if (rdata.length > 0) {
              _nobj.title = rdata[rdata.length - 1].title
              _nobj.titleLab = _nobj.title + '(新_' + (rdata.length + 1) + ')'
          }
          _nobj.special = true
          _nobj.sidebarHide = true
          _nobj.start = st
          _nobj.end = et
          _nobj.numberSettings = [{
              endHour: _nobj.end.split(':')[0] * 1,
              endMinute: _nobj.end.split(':')[1] * 1,
              preKey: "",
              startHour: _nobj.start.split(':')[0] * 1,
              startMinute: _nobj.start.split(':')[1] * 1,
              startNum: 1
          }]
          rdata.push(_nobj)
      }
  }
  console.log('rdata', rdata)
  return rdata
}

/**
 * 计算当前选择模块的可选择时间范围
 * @param {*} time 当前选择的时间段模块 08:00-09:00
 * @param {*} timeArr 当前选择时段、当前日期，已经选择的所有时段模块
 * @param {*} startTime 当前班次的开始时间
 * @param {*} endTime 当前班次的结束时间
 * @returns 08:00-10:00
 * 最小值计算方式：
 *  1、判断已选择模块的最小时间与最大时间分别小于等于当前选择模块
 *  2、如果已经赋值过一次的情况，则判断赋值后的最小值是否大于已选模块的最大值
 * 最大值计算方式：如上
 */
export const calMaxMinTime = (time, timeArr, startTime, endTime) => {
    if (!time && !startTime && !endTime) {
        return null
    }
    const colAppos = flattenDeep(timeArr).filter(ap => !ap.isAddBox)
    const Len = colAppos.length
    let minTime = time.split('-')[0]
    let maxTime = time.split('-')[1]
    let minTimez = time.split('-')[0]
    let maxTimez = time.split('-')[1]
    let minAdd = 0 // 判断最小值是否有改变
    let maxAdd = 0 // 判断最大值是否有改变
        // let tAMin = null
        // let tAMax = null

    if (Len > 0) {
        // 如果当前时段有已添加号源执行
        let maxMinz = maxTimez.split(':')[0] * 60 + maxTimez.split(':')[1] * 1
        let minMinz = minTimez.split(':')[0] * 60 + minTimez.split(':')[1] * 1
        for (let i = 0; i < Len; i++) {
            let maxMin = maxTime.split(':')[0] * 60 + maxTime.split(':')[1] * 1
            let minMin = minTime.split(':')[0] * 60 + minTime.split(':')[1] * 1
            let startMin = colAppos[i].beginTime.split(':')[0] * 60 + colAppos[i].beginTime.split(':')[1] * 1
            let endMin = colAppos[i].endTime.split(':')[0] * 60 + colAppos[i].endTime.split(':')[1] * 1
            if (startMin <= minMinz && endMin <= maxMinz) {
                if (minAdd === 0) {
                    // 第一次计算，赋值小的值
                    minTime = colAppos[i].endTime
                } else {
                    // 多次计算，赋值大的值
                    minTime = minMin >= endMin ? minTime : colAppos[i].endTime
                }
                minAdd++
            }
            if (startMin >= minMinz && endMin >= maxMinz) {
                if (maxAdd === 0) {
                    // 第一次计算赋值大的值
                    maxTime = colAppos[i].beginTime
                } else {
                    // 多次计算赋值小的值
                    maxTime = maxMin <= startMin ? maxTime : colAppos[i].beginTime
                }
                maxAdd++
            }

            // tAMin = tAMin ? getCalTimeMinute(tAMin) < colAppos[i].beginTime ? tAMin : colAppos[i].beginTime : colAppos[i].beginTime
            // tAMax = tAMax ? getCalTimeMinute(tAMax) > colAppos[i].endTime ? tAMax : colAppos[i].endTime : colAppos[i].endTime
        }
    }
    // // console.log(tAMin, tAMax)
    if (minTime === minTimez && minAdd === 0) {
        minTime = this.appoRepair ? minTime : startTime || minTime
    }
    if (maxTime === maxTimez && maxAdd === 0) {
        maxTime = this.appoRepair ? maxTime : endTime || maxTime
    }
    if (minAdd + maxAdd === Len || appoRepair) {
        return minTime + '-' + maxTime
    } else {
        return null
    }
}

/**
 * 计算两个时间段的相交
 * @param {*} timeCur 时间段1
 * @param {*} timeOpt 时间段2
 * @returns 返回时段的交集
 */
export const calTimeSelected = (timeCur, timeOpt) => {
    // console.log('calTimeSelected', timeCur, timeOpt)
    try {
        let resMin = null
        let resMax = null
        const ctarr = timeCur.split('-')
        const otarr = timeOpt.split('-')
        const ctMin = ctarr[0].split(':')[0] * 60 + ctarr[0].split(':')[1] * 1
        const ctMax = ctarr[1].split(':')[0] * 60 + ctarr[1].split(':')[1] * 1
        const otMin = otarr[0].split(':')[0] * 60 + otarr[0].split(':')[1] * 1
        const otMax = otarr[1].split(':')[0] * 60 + otarr[1].split(':')[1] * 1
        resMin = ctarr[0]
        if (ctMin < otMin) {
            resMin = otarr[0]
        }
        resMax = ctarr[1]
        if (ctMax > otMax) {
            resMax = otarr[1]
        }
        return resMin + '-' + resMax
    } catch (err) {
        console.error(err)
    }
}
/**
 * 计算起始号码、数据排序(增加号源数量的时候才会考虑重新排序，减少号源的时候不会去重新排序，这是医院那边的需求，不过经过医院实地考察，对于有使用签到分诊系统的，加减号重新排序是无所谓的，因为签到的时候会重新分配排序号；对于无需签到的医院，最好还是不要去重新排序，不然之前拿到号的患者于重新排序后的序号，会乱套的，为了避免这种情况，所以对于无需签到的医院或医院里的某个检查部门，1.全天号源不能连续，2.加号只能加在每个班次的最后一个时段)
 * @param {*} data 排班数据数组，该函数会把号源数组进行按照开始时间排序，也会把时间有问题的数据给过滤掉
 * @param {*} checkClass 计算班次
 * @param {*} continuation 连续
 * @param {*} checkClassData 班次数据
 * @param {*} _ccIndex
 * @returns
 */
export const calAppoInitialNum = (data, checkClass, continuation, checkClassData, _ccIndex) => {
  // console.log('进入calAppoInitialNum=>data', data)
  // checkClassData = getSidebarData()
  // console.log('竖向时间轴里的数据checkClassData', checkClassData)
  return new Promise(resolve => {
    let appoArr = [...data.filter(item => !item.isAddBox)]
    // cCheckData 号源列表竖向时间轴00:00~8:30 8:30~12:00 12:00~24:00
    const cCheckData = typeof _ccIndex === 'number' ? checkClassData[_ccIndex] : null
    const c_beginTime = cCheckData ? cCheckData.start : '00:00'
    const c_endTime = cCheckData ? cCheckData.end : '24:00'
    const checkClass_bt = getCalTimeSecond(c_beginTime)
    const checkClass_et = getCalTimeSecond(c_endTime)
    const checkClassMinTime = typeof _ccIndex === 'number' ? checkClass_bt : 0
    const checkClassMaxTime = typeof _ccIndex === 'number' ? checkClass_et : 0
    let resArr = []
    let lastInitialNum = 0 // 下一个号源的初始号
    let addTime = getCalTimeSecond(_startTime)
    const _getAddObj = (beginTime, endTime, cc) => {
      return {
        beginTime,
        endTime,
        checkClass: cc || checkClass,
        time: `${beginTime}-${endTime}`,
        preKey: '',
        startNum: 1,
        isAddBox: true
      }
    }
    const printResArr = (resArr) => {
      resArr.forEach(item => {
        // console.log(`item.beginTime~item.endTime:${item.beginTime}~${item.endTime},item.checkClass:${item.checkClass}`)
      })
    }
    if (appoArr.length) {
      const sortData = (a, b) => {
        const aa = getCalTimeSecond(a.beginTime)
        const bb = getCalTimeSecond(b.beginTime)
        return aa - bb
      }
      appoArr.sort(sortData)
      // console.log('appoArr======================',appoArr)
      let curIndex = 0
      // 啊 这里面自动修复了时间，需要排查，不要修复
      appoArr.forEach((item, index) => {
        // console.log('-----index--------', index)
        const _bt = getCalTimeSecond(item.beginTime)
        const _et = getCalTimeSecond(item.endTime)
        const _preEt = curIndex === 0 ? checkClass_bt < addTime ? addTime : checkClass_bt : getCalTimeSecond(appoArr[index - 1].endTime)
        // 并且当前开始时间!=时间轴中该班次的开始时间
        if (appoRepair && _bt > _preEt && _preEt < checkClass_et && checkClass == item.checkClass && _bt != checkClass_bt) {
          // 根据item.beginTime判断班次，然后判断appoArr[index - 1].endTime是否属于当前班次，若是取appoArr[index - 1].endTime，否则取当前班次起始时间
          let addStartTime = ''
          let className = getSeasonDateTitle({
            appointmentDate: null,
            beginTime: appoArr[index - 1] ? appoArr[index - 1].endTime : cCheckData.start,
            endTime: item.beginTime,
            checkClassData
          })
          // console.log('className', className)
          // console.log('checkClass', checkClass)
          if (className == checkClass) {
            addStartTime = appoArr[index - 1] ? appoArr[index - 1].endTime : cCheckData.start
          } else {
            // console.log('checkClassData', checkClassData)
            // console.log('getSidebarDataTemp()=》', getSidebarDataTemp())
            const sidebarData = checkClassData || getSidebarData() || getSidebarDataTemp()
            let classData = ''
            sidebarData.forEach(item => {
              if (item.title == checkClass) {
                classData = item
              }
            })
            addStartTime = classData.start
          }
          let getAddObj = _getAddObj(curIndex === 0 ? c_beginTime : addStartTime, item.beginTime, checkClass) // 20231113号修改后的代码
          // console.log('resArr.push=>getAddObj', getAddObj)
          resArr.push(getAddObj)
          printResArr(resArr)
        }
        curIndex++
        if ((item.checkClass === checkClass &&  checkClass == cCheckData.title )  || getContinuityNum()) {
          // checkNum：号源数，reserveNum：预留，addNum：追加数，initialNum:起始号码，callNum：已预约数
          // console.log('打印咯Item', item)
          // console.log('item.checkNum', item.checkNum)
          let midNum = 0 // 当所加号源的个数超过下一个时间段号源的起始排队号的时候，这当中所相差的个数
          // getArgsCalNum计算所传参数的所有和
          let tNum = getArgsCalNum(item.checkNum, item.reserveNum, item.addNum, item.callNum)
          // 如果为0，让占一个号源，不然会有BUG
          if (tNum == 0) {
            tNum = 1
          }
          // console.log('==================')
          // console.log('item.initialNum', item.initialNum)
          // console.log('continuation', continuation)
          // console.log('lastInitialNum', lastInitialNum)
          // lastInitialNum:下一个号源的初始号
          if (item.initialNum < lastInitialNum || continuation) {
            if (lastInitialNum === 0) {
                // 第一个循环的时候把初始值设置为第一个的初始号码
                lastInitialNum = item.initialNum * 1
            }
            // console.log('item.initialNum=>', item.initialNum)
            // console.log('and', getArgsCalNum(appoArr[index - 1].checkNum, appoArr[index - 1].reserveNum, appoArr[index - 1].addNum, appoArr[index - 1].callNum) + Number(appoArr[index - 1].initialNum))
            item.initialNum = lastInitialNum + ''
            // if (item.initialNum >= getArgsCalNum(appoArr[index - 1].checkNum, appoArr[index - 1].reserveNum, appoArr[index - 1].addNum, appoArr[index - 1].callNum) + lastInitialNum) {
            //   item.initialNum = lastInitialNum + ''
            // }
            // console.log('item.initialNum', item.initialNum)
          } else {
            midNum = item.initialNum - lastInitialNum
            // console.log('-----------------------------')
            // console.log('midNum', midNum)
            // console.log('midNum > 0')
          }
          // console.log('tNum', tNum)
          const curInitialNum = midNum + tNum
          // console.log('curInitialNum', curInitialNum)
          // console.log('lastInitialNum1', lastInitialNum)
          lastInitialNum = lastInitialNum + curInitialNum
          // console.log('lastInitialNum2', lastInitialNum)
        }
        if ((appoRepair && item.checkClass === checkClass && checkClass === cCheckData.title && item.beginTime < cCheckData.end) ||
        checkClassMaxTime === 0 || checkClass === '' || (_bt >= checkClassMinTime && _et <= checkClassMaxTime && item.checkClass === checkClass)) {
          // 添加号源
          resArr.push(item)
          printResArr(resArr)
        }
        addTime = getCalTimeSecond(item.endTime)
      })
    }
    if (appoRepair && !resArr.length) {
      let getAddObj = _getAddObj(c_beginTime, c_endTime)
      resArr.push(getAddObj)
      printResArr(resArr)
    } else if (resArr.length) {
      const _firstAppo = resArr[0]
      const _lastAppo = resArr[resArr.length - 1]
      const _lastEndTime = getCalTimeSecond(_lastAppo.endTime)
      if (appoRepair && _lastEndTime < checkClass_et && _lastEndTime < getCalTimeSecond('23:59')) {
        let getAddObj = _getAddObj(_lastAppo.endTime, c_endTime, _lastAppo.checkClass)
        resArr.push(getAddObj)
        printResArr(resArr)
      }
    }
    printResArr(resArr)
    resolve(resArr)
  })
}

/**
 * 计算，参数模板加入时的时间区间
 * @param {*} appoArr 已存在的时段
 * @param {*} newObj 参数模板新增时段
 * @returns
 */
export function calNewAppoTime(appoArr, newObj, soTime, eoTime) {
    return new Promise(resolve => {
        let _newObj = {...newObj }
        const len = appoArr.length
        const minTime = newObj.beginTime
        const maxTime = newObj.endTime
        const secTime = newObj.secTime
        let soMin = soTime.split(':')[0] * 60 + soTime.split(':')[1] * 1
        let eoMax = eoTime.split(':')[0] * 60 + eoTime.split(':')[1] * 1
        let minMin = minTime.split(':')[0] * 60 + minTime.split(':')[1] * 1
        let maxMin = maxTime.split(':')[0] * 60 + maxTime.split(':')[1] * 1
        let secMin = secTime.split(':')[0] * 60 + secTime.split(':')[1] * 1
        if (maxMin - minMin <= 30) {
            // 如果选中的时间区间小于30
            resolve(_newObj)
        }
        let cMin = soMin
        let cMax = eoMax // 最大值只用赋值一次
        for (let i = 0; i < len; i++) {
            let startMin = appoArr[i].beginTime.split(':')[0] * 60 + appoArr[i].beginTime.split(':')[1] * 1
            let endMin = appoArr[i].endTime.split(':')[0] * 60 + appoArr[i].endTime.split(':')[1] * 1
                // // console.log('beginTime22222',appoArr[i].beginTime)
                // // console.log('endTime22222',appoArr[i].endTime)

            if ((startMin === minMin && endMin < maxMin) || endMin <= minMin || (endMin > minMin && endMin < maxMin && startMin < minMin)) {
                // 下包含
                cMin = endMin
            } else if (endMin === maxMin && startMin > minMin || (cMax === eoMax && startMin >= maxMin) || (startMin > minMin && startMin < maxMin && endMin > maxMin)) {
                // 上包含
                cMax = startMin
            }
        }
        // // console.log('cMincMincMin',minMin, cMin)
        // // console.log('cMaxcMaxcMax',maxMin, cMax)
        // // console.log('secMinsecMin',secMin)

        // 判断，赋值符合插入的时段时间区间
        maxMin = secMin
        if (minMin < cMin) {
            const c = cMin - minMin
            minMin = cMin
            if (secMin + c <= cMax) {
                maxMin = secMin + c
            }
        }
        if (secMin > cMax) {
            const m = secMin - cMax
            maxMin = cMax
            if (minMin - m >= cMin) {
                minMin = minMin - m
            }
        }

        let bth = Math.floor(minMin / 60)
        let btm = Math.floor(minMin % 60)
        bth = bth < 10 ? '0' + bth : bth
        btm = btm > 0 ? btm : '00'
        let eth = Math.floor(maxMin / 60)
        let etm = Math.floor(maxMin % 60)
        eth = eth < 10 ? '0' + eth : eth
        etm = etm > 9 ? etm : '0' + etm
        _newObj.beginTime = bth + ':' + btm
        _newObj.endTime = eth + ':' + etm

        resolve(_newObj)
    })
}

/**
 * 根据传输的时间算时间间隔，再累加开始时间，返回对应的结束时间
 * @param {*} beginTime1 开始时间1
 * @param {*} endTime1 结束时间1
 * @param {*} beginTime2 开始时间2
 * @returns endTime2 结束时间2
 */
export function timeTransferInterval(beginTime1, endTime1, beginTime2) {
    const tMin1 = beginTime1.split(':')[0] * 60 + beginTime1.split(':')[1] * 1
    const tMax1 = endTime1.split(':')[0] * 60 + endTime1.split(':')[1] * 1
    const tMin2 = beginTime2.split(':')[0] * 60 + beginTime2.split(':')[1] * 1
    const time1 = tMax1 - tMin1
    const tMax2 = tMin2 + time1
    let endTime2 = ''
    if (tMax2 >= 1440) {
        endTime2 = '24:00'
    } else {
        const t1 = Math.floor(tMax2 / 60)
        const t2 = tMax2 % 60
        endTime2 = `${t1}:${t2>9?t2:'0'+t2}`
    }
    // // console.log('beginTime2beginTime2', beginTime2, endTime2)
    return endTime2
}

/**
 * 计算时间段，返回时间段数据、时段单元高度
 * @param {*} data
 * @param {*} rowHeight
 * @returns
 */
export function getInitTimeGroud(data, rowHeight) {
    /**
     * start 开始时间 8:30
     * end 结束时间 12:00
     * numberSettings 时段规则设置列表[{}]
     * special 特定班次，不在班次时段内的班次时间
     *    endHour: 12
          endMinute: 30
          preKey: "D"
          startHour: 8
          startMinute: 30
          startNum: 4
     *
     * sTime 时间段
     * height 时段的高度单元
     * barHeight 时段总高度
     * */
    let { start, end, numberSettings, special } = data
    // special = false
    let sTime = []
    let barHeight = 0
    let hTime = []
    let hBarHeight = 0
    if (start && end) {
        let startTime = start.split(':')[0] * 1
        let startTimeH = start.split(':')[1] * 1
        let endTime = end.split(':')[0] * 1
        let endTimeH = end.split(':')[1] * 1
        hTime.push({
            time: start + '-' + end,
            height: 60,
            heightpx: (1 * rowHeight / 2) + 'px',
            startNum: numberSettings[0].startNum,
            preKey: numberSettings[0].preKey
        })
        hBarHeight = (1 * rowHeight / 2)
            // if (special) {
            //   sTime.push({
            //     time: start+'-'+end,
            //     height: 60,
            //     heightpx: 1 * rowHeight + 'px',
            //     startNum: numberSettings[0].startNum,
            //     preKey: numberSettings[0].preKey
            //   })
            //   barHeight = 1 * rowHeight
            // } else {
        for (let i = startTime; i <= endTime; i++) {
            let h = i
            let tt = ''
            let hh = 0
            if (i === startTime && startTimeH !== 0) {
                // 开始时间，如果不是整点
                tt = h + ':' + startTimeH + '-' + (h + 1) + ':00'
            } else if (i === endTime && endTimeH !== 0) {
                // 结束时间，如果不是整点，加上面后面的时间
                tt = h + ':00' + '-' + h + ':' + endTimeH
            } else if (i < endTime) {
                // 结束时间
                tt = h + ':00' + '-' + (h + 1) + ':00'
            }
            // 计算,时间段单元
            hh = calTimeUnit(tt)
            hh = i === startTime && startTimeH !== 0 ? 60 - hh : hh
            hh = hh < 30 && hh >= 5 ? 30 : hh
            barHeight += (hh / 60) * rowHeight
            if (tt && hh) {
                sTime.push({
                    time: tt,
                    height: hh,
                    heightpx: (hh / 60) * rowHeight + 'px',
                    startNum: numberSettings[0].startNum,
                    preKey: numberSettings[0].preKey
                })
            }
        }
        // }

    } else {
        sTime = [
            { time: '8:00-9:00', height: 60, heightpx: rowHeight + 'px', startNum: numberSettings[0].startNum, preKey: numberSettings[0].preKey },
            { time: '9:00-10:00', height: 60, heightpx: rowHeight + 'px', startNum: numberSettings[0].startNum, preKey: numberSettings[0].preKey },
            { time: '10:00-11:00', height: 60, heightpx: rowHeight + 'px', startNum: numberSettings[0].startNum, preKey: numberSettings[0].preKey },
            { time: '11:00-12:00', height: 60, heightpx: rowHeight + 'px', startNum: numberSettings[0].startNum, preKey: numberSettings[0].preKey }
        ]
        barHeight = 4 * rowHeight
        hTime.push({ time: '8:00-12:00', height: 60, heightpx: rowHeight + 'px', startNum: numberSettings[0].startNum, preKey: numberSettings[0].preKey })
        hBarHeight = 1 * rowHeight
    }

    return {
        hbh: hBarHeight, // 班次高度 收起
        htg: JSON.parse(JSON.stringify(hTime)), // 班次时段数组 收起
        sbh: barHeight, // 班次高度 展开
        stg: JSON.parse(JSON.stringify(sTime)) // 班次时段数组 展开
    }
}
// 计算时间段单元
export function calTimeUnit(time) {
    let tu = 0
    if (time) {
        let s = getTimeUnit(time.split('-')[0])
        let e = getTimeUnit(time.split('-')[1])
        tu = s <= e ? s : e
    }
    return tu
}
// 计算时间段单元，时间
export function getTimeUnit(t) {
    // t 8:00
    let u = 60
    if (t) {
        let tEnd = t.split(':')[1] * 1
        u = tEnd > 0 ? tEnd : u
    } else {
        u = 0
    }
    return u
}

/**
 * 计算号源的dom样式， style
 * @param {*} timeObj
 * @param {*} appoObj
 * @param {*} rowHeight
 * @returns
 */
export function calAppoStyleObj(timeObj, appoObj, rowHeight, timeObjNext, index) {
    // console.log('calAppoStyleObj=>timeObj, appoObj, rowHeight', timeObj, appoObj, rowHeight)
    // console.log('=================')
    // console.log('appoObj', appoObj)
    // console.log('timeObj', timeObj)
    // console.log('timeObjNext', timeObjNext)
    // console.log('index', index)
    // console.log('=================')
    // setLocalStorage('yjyy-repair-opp', '')
    if (isNull(timeObj)) return null
    let minTime = timeObj.start // 00:00
    let maxTime = timeObj.end // 08:30
    let minMin = minTime.split(':')[0] * 60 + minTime.split(':')[1] * 1 // 0
    let maxMin = maxTime.split(':')[0] * 60 + maxTime.split(':')[1] * 1 // 08 * 60 + 30
    let minSc = minTime.split(':')[1] * 1
    minSc = minSc === 0 ? minSc : 60 - minSc
        // // console.log('minMin:==', minMin)
        // // console.log('maxMin:==', maxMin)
        // // console.log('minTime:==', minTime)
        // // console.log('maxTime:==', maxTime)
    if (appoObj && typeof appoObj === 'object') {
        appoObj.isBad = false
        appoObj.totalNum = getArgsCalNum(appoObj.checkNum, appoObj.reserveNum, appoObj.addNum, appoObj.callNum)
        let timeArr_b = appoObj.beginTime.split(':') // ['00','00']
        let timeArr_e = appoObj.endTime.split(':') // ['12','00']
        let startMin = timeArr_b[0] * 60 + timeArr_b[1] * 1 // 0
        let endMin = timeArr_e[0] * 60 + timeArr_e[1] * 1 // 12 * 60 + 0
        // // console.log('calAppoStyleObj __  appoObj.endTime', appoObj.endTime) // 12:00:00
        // // console.log('startMin', startMin)
        // // console.log('endMin', endMin)
        // // console.log('minMin', minMin)
        // // console.log('maxMin', maxMin)
        // 啊，由于有些医院班次跨越上下午的需求，比如号源班次时间是10:00~14:00的，就不好去判断时间了，所以暂时还是不去判断智能修正时间
        // startMin endMin 是号源当前时间段的开始时间与结束时间
        // minMin maxMin 是时令上的最小最大时间段
        // startMin:720,minMin:0,endMin:810,maxMin:720
        // startMin:810,minMin:0,endMin:840,maxMin:720
        // console.log(`startMin:${startMin},minMin:${minMin},endMin:${endMin},maxMin:${maxMin}`)
        if (startMin < minMin || endMin > maxMin) {
            if (startMin > maxMin) {
                // console.log('========return null==========')
                // return null
            }
            // startMin = startMin < minMin ? minMin : startMin
            startMin = startMin < minMin ? startMin : startMin // 为了不修复时间全部取startMin
            // endMin = endMin > maxMin ? maxMin : endMin
            endMin = endMin > maxMin ? endMin : endMin // 为了不修复时间全部取endMin
            appoObj.oldBeginTime = appoObj.beginTime
            appoObj.oldEndTime = appoObj.endTime
            // 设置班次的可选择时间段时间
            appoObj.selectTimeStart = minTime
            appoObj.selectTimeEnd = maxTime
            appoObj.isBad = false
            // appoObj.isBad = true
        }
        let sh = Math.floor(startMin / 60) // 8
        let sm = startMin % 60 // 0
        let eh = Math.floor(endMin / 60) // 12
        let em = endMin % 60 // 0
        sh = sh < 10 ? '0' + sh : sh
        sm = sm < 10 ? '0' + sm : sm
        eh = eh < 10 ? '0' + eh : eh
        em = em < 10 ? '0' + em : em
        appoObj.beginTime = sh + ':' + sm
        appoObj.endTime = eh + ':' + em // 20231109号注释 不能智能修复时间了，但注释后数据会乱，还需要看看
        // // console.log('===appoObj.endTime===', appoObj.endTime)
        let difMin = endMin - startMin
            // // console.log('endMin:==', endMin)
            // // console.log('startMin:==', startMin)
            // // console.log('difMin:==', difMin)
            // // console.log('top:==', startMin - minMin)
        let t = (startMin - minMin)
        let setop = t === 0 ? 0 : t - minSc + (minSc > 5 && minSc < 30 ? 30 : minSc)
        difMin = difMin > 30 && t === 0 ? difMin - minSc + (minSc > 5 && minSc < 30 ? 30 : minSc) : difMin
        appoObj.appoStyle = {
            height: difMin * rowHeight / 60 + 'px',
            top: (setop * rowHeight / 60) + 'px'
        }
        // 修复班次，以开始时间为主
        // appoObj.checkClass = timeObj.title
        // console.log('================')
        // console.log('appoObj.beginTime', appoObj.beginTime)
        // console.log('timeObj.end', timeObj.end)
        // console.log('================')
        // if (appoObj.beginTime >= timeObj.end) {
        //   // console.log('来到这里')
        //   appoObj.checkClass = timeObjNext.title
        // } else {
        //   appoObj.checkClass = timeObj.title
        // }
        // console.log('appoObj', appoObj)
        // console.log('timeObj', timeObj)
        // console.log('来到这里囖囖咯')
        // console.log('getCalTimeMinute(appoObj.beginTime)', getCalTimeMinute(appoObj.beginTime))
        // console.log('getCalTimeMinute(timeObj.start)', getCalTimeMinute(timeObj.start))
        // console.log('getCalTimeMinute(appoObj.endTime)', getCalTimeMinute(appoObj.endTime))
        // console.log('getCalTimeMinute(timeObj.end)', getCalTimeMinute(timeObj.end))
        if (!isNull(timeObj) && (getCalTimeMinute(appoObj.beginTime) >= getCalTimeMinute(timeObj.start) && getCalTimeMinute(appoObj.endTime) <= getCalTimeMinute(timeObj.end)) || (getCalTimeMinute(appoObj.beginTime) >= getCalTimeMinute(timeObj.start) && getCalTimeMinute(appoObj.endTime) >= getCalTimeMinute(timeObj.end))) {
          const lastCheckClass = appoObj.checkClass
          // console.log('lastCheckClass', lastCheckClass)
          // appoObj.checkClass = timeObj.title
          // if (lastCheckClass != timeObj.title) {
          //   setLocalStorage('isRepairCheckClass', 1)
          //   // 把因时令改变后而重组的号源缓存起来
          //   let repairOppList = getLocalStorage('yjyy-repair-opp')
          //   if (!repairOppList) {
          //     repairOppList = []
          //   } else {
          //     repairOppList = JSON.parse((repairOppList))
          //   }
          //   repairOppList.push(appoObj)
          //   setLocalStorage('yjyy-repair-opp', JSON.stringify(repairOppList))
          // }
          // console.log('appoObj.beginTime', appoObj.beginTime)
          // console.log('timeObj.end', timeObj.end)
          if (appoObj.beginTime >= timeObj.end) {
            // console.log('来到这里111')
            appoObj.checkClass = timeObjNext.title
            if (lastCheckClass != timeObjNext.title) {
              setLocalStorage('isRepairCheckClass', 1)
              // 把因时令改变后而重组的号源缓存起来
              let repairOppList = getLocalStorage('yjyy-repair-opp')
              if (!repairOppList) {
                repairOppList = []
              } else {
                repairOppList = JSON.parse((repairOppList))
              }
              repairOppList.push(appoObj)
              setLocalStorage('yjyy-repair-opp', JSON.stringify(repairOppList))
            }
          } else {
            // console.log('全部来到这里了吧')
            appoObj.checkClass = timeObj.title
            if (lastCheckClass != timeObj.title) {
              setLocalStorage('isRepairCheckClass', 1)
              // 把因时令改变后而重组的号源缓存起来
              let repairOppList = getLocalStorage('yjyy-repair-opp')
              if (!repairOppList) {
                repairOppList = []
              } else {
                repairOppList = JSON.parse((repairOppList))
              }
              repairOppList.push(appoObj)
              setLocalStorage('yjyy-repair-opp', JSON.stringify(repairOppList))
            }
          }
        } else {
          if (appoObj.beginTime < timeObj.start && appoObj.endTime <= timeObj.start) {
            // console.log('来到这里222')
            appoObj.checkClass = timeObjNext.title
          } else {
            appoObj.checkClass = timeObj.title
          }
        }
        appoObj.appoSize = difMin
    }
    // console.log('处理该号源后得到appoObj', appoObj)
    appoObj.avgNum = appoObj.callNum
    return appoObj
}
